package com.znyj.servlet.mainController;

import com.znyj.servlet.entity.UserEntity;
import com.znyj.servlet.model.UserQueryModel;
import com.znyj.servlet.service.UserService;
import com.znyj.servlet.vo.Page;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by gaoliwei02 on 17/7/8.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;

    @RequestMapping(value = "/getlist.inner", method = RequestMethod.POST)
    protected @ResponseBody String getlistInner(@RequestBody String receiveData){

        UserQueryModel userQueryModel = new UserQueryModel(receiveData);//string到pojo
        Page<UserEntity> page = userService.createUserPage(userQueryModel);//从数据库获取实体列表

        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").disableHtmlEscaping().create();
        return gson.toJson(page);
    }

    /*-----------------------------PAGE-----------------------------------------------------*/
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    protected String index(HttpServletRequest request) {
        return "/page/user_page";
    }

}
